var chalk = require('chalk');
var FsUtils = require('../utils/FsUtils.js');
var paramsUtils = require("../utils/ParamsUtils.js");

const pluginName = 'DistInitPlugin';

class DistInitPlugin {
    apply(compiler) {
        //生成资源到 output 目录之前
        compiler.hooks.emit.tap(
            pluginName,
            (compilation) => {
                console.log(``);
                console.log(chalk.green(`执行--->${pluginName}`));
                // 如果是seeyon编译，则清空dist
                if(paramsUtils.isExist('--seeyon') ){
                    console.log('----------------------')
                    FsUtils.emptyDir('seeyon');
                    FsUtils.emptyDir('dist');
                    FsUtils.emptyDir('dist_back');
                }
            }
        );
    }
}

module.exports = DistInitPlugin;